package com.example.campus.controller.user;

import com.example.campus.pojo.dto.CommentPageQueryDTO;
import com.example.campus.pojo.dto.CommentPublishDTO;
import com.example.campus.pojo.entity.Comment;
import com.example.campus.pojo.vo.CommentVO;
import com.example.campus.result.PageResult;
import com.example.campus.result.Result;
import com.example.campus.service.CommentService;
import com.example.campus.utils.constant.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userCommentController")
@RequestMapping("/user/comment")
@Slf4j
@Api(tags = "用户端评论相关接口")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/list/{infoId}")
    @ApiOperation("评论信息查询(不分页)")
    public Result<List<CommentVO>> commentList(@PathVariable("infoId") Long infoId) {
        List<CommentVO> commentVOs = commentService.getCommentByInfoId(infoId);
        return Result.success(commentVOs);
    }

    @PostMapping("/publish")
    @ApiOperation("对失物/寻物信息发布评论")
    public Result publish(@RequestBody @Validated CommentPublishDTO commentPublishDTO) {
        commentService.publishComment(commentPublishDTO);
        return Result.success(MessageConstant.PUBLISH_SUCCESS);
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除评论（用户自身的评论和帖主对所有人）")
    public Result delete(@PathVariable("id") Long id) {
        commentService.deleteComment(id);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }
}
